//
//  Beauty.swift
//  4-5classWork
//
//  Created by Qingke on 16/4/6.
//  Copyright © 2016年 Qingke. All rights reserved.
//

import UIKit
class Beauty : NSObject , NSCoding{
    var name :String = ""
    var photo: UIImage?
    var ranting : Double = 0.0
    
    static let DocumentDirectory = NSFileManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!
    static let ArchiveURl = DocumentDirectory.URLByAppendingPathComponent("beauty")
    init? (name : String , photo : UIImage? ,ranting : Double) {
        self.name = name
        self.photo = photo
        self.ranting = ranting
        super.init()
        if name.isEmpty  || ranting < 0.0 {
            return nil
        }
    }
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder .encodeObject(name, forKey: "name")
        aCoder .encodeObject(photo, forKey: "photo")
        aCoder .encodeDouble(ranting, forKey: "ranting")
        
    }
    
    required convenience  init?(coder aDecoder: NSCoder) {
        let name = aDecoder.decodeObjectForKey("name") as! String
        let photo = aDecoder.decodeObjectForKey("photo") as? UIImage
        let ranting = aDecoder.decodeDoubleForKey("ranting")
        self.init(name: name, photo: photo, ranting :ranting)
    }


}


    
    